<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    // json 的3种数据格式
    // json 对象
    let json1 = {age: 18, name:"张三", sex:"男"};
    console.log(typeof json1);
    console.log(json1);

    console.log(json1.age);
    console.log(json1.name);
    console.log(json1.sex);


    console.log(json1["age"]);
    console.log(json1["name"]);
    console.log(json1["sex"]);

    // json数组
    console.log("-----------");
    let json2 = ["jack", "tom", "rose", "jerry"];
    console.log(typeof json2);
    console.log(json2[0]);
    console.log(json2[1]);
    console.log(json2[2]);
    //json混合对象
    console.log("------");
    let json3 = [{name: "张三",age:18}, {name: "李四", age: 19}, {name: "王五", age: 22}];
    console.log(json3);

    console.log(json3[1].name);

    // json 转成String
    let json1 = {name:"张三",age:18,password:"123321"};
    console.log(json1);

    // string 转成 json
    console.log("------");
    let json2 = JSON.parse(jsonStr);

    console.log(typeof json2);
    console.log(json2);
</script>
</body>
</html>